
/*
 * @Author: ljkt
 * @Version: 2.0
 * @Date: 2021-12-01 14:27:01
 * @LastEditors: ljkt
 * @LastEditTime: 2025-06-30 11:04:13
 * @Description:
 */

#include "./Common_Include.h"
#if defined(EN_PWM0) || defined(EN_PWM1) || defined(EN_PWM2)
CONST s_hal_pwmx_config_t pwmx_config_tab[e_HAL_PWM_MAX] = {
#ifdef EN_PWM_BUZ
    DRV_PWM_BUZ_CONFIG,
#endif
#ifdef EN_PWM_BUZXY
    DRV_PWM_BUZ_CONFIG,
#endif
#ifdef EN_PWM_BUZ_SETTIME
    DRV_PWM_BUZ_CONFIG,
#endif
};
Ram s_drv_pwmx_t gDrvPwm[e_HAL_PWM_MAX];
void Drv_Pwm_Set_Duty(unsigned char index, unsigned char duty)
{
    gDrvPwm[index].Duty = duty;
    Hal_Pwmx_Duty(&pwmx_config_tab[index], pwmx_config_tab[index].freq, duty);
}
void Drv_Pwmx_Init(void)
{
    unsigned char i;
    memset(&gDrvPwm, 0, sizeof(gDrvPwm));
    for (i = 0; i < ARR_CNT(pwmx_config_tab); i++)
    {
        gDrvPwm[i].F = pwmx_config_tab[i].freq;
        Hal_Pwmx_Init(&pwmx_config_tab[i]);
    }
}

void Drv_Pwmx_Scan(void)
{
    static unsigned char tick = 0;
    unsigned char i;
    if (Drv_Autoload_Ntick_u8(&tick, 20ul))
    {
        for (i = 0; i < ARR_CNT(pwmx_config_tab); i++)
        {
            Hal_Pwmx_Duty(&pwmx_config_tab[i], gDrvPwm[i].F, gDrvPwm[i].Duty);
        }
    }
}
#endif